package com.gency.subscribe.web.controller.system;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gency.subscribe.model.system.MapInfo;
import com.gency.subscribe.service.system.IMapInfoService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 马行空
 * @since 2018-06-12
 */
@Controller
@RequestMapping("/mapInfo")
public class MapInfoController {

	@Autowired
	IMapInfoService mapInfoService;
	
	
	/**
	 * 查询所有的一级分类
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/fistLeve")
	public List<MapInfo> getFirstUnitCategory(){
		EntityWrapper<MapInfo> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("level", 1);
		return mapInfoService.selectList(entityWrapper);
	}
	
	
	/**
	 * 2级分类
	 * @param fistCode
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/secendLeve")
	public List<MapInfo> getSecendUnitCategory(String fistCode){
		EntityWrapper<MapInfo> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("level",2);
		entityWrapper.eq("parentCode", fistCode);
		List<MapInfo> list = mapInfoService.selectList(entityWrapper);
		return list;
	}
	
	/**
	 * 三级分类
	 * @param secendCode
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/threeLeve")
	public List<MapInfo> getThreeUnitCategory(String secendCode){
		EntityWrapper<MapInfo> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("level",3);
		entityWrapper.eq("parentCode", secendCode);
		List<MapInfo> list = mapInfoService.selectList(entityWrapper);
		return list;
	}
	
	/**
	 * 4级分类
	 * @param threedCode
	 * @return
	 */
	@ResponseBody
	@GetMapping(value="/fourLeve")
	public List<MapInfo> getFourUnitCategory(String threedCode){
		EntityWrapper<MapInfo> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("level",4);
		entityWrapper.eq("parentCode", threedCode);
		List<MapInfo> list = mapInfoService.selectList(entityWrapper);
		return list;
	}
	
}

